#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using Agresso.Interface.Layer.Service;
using System.Collections;
using System.IO;
using System.Configuration;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class UserControlCompasCrewPayroll : UserControl
    {
        User m_current_user;
        MainForm m_mainForm;
        //WinSDSService m_WinSDSService;
        CrewPayrollService m_CrewPayrollService;
        string m_startDefault;

        public UserControlCompasCrewPayroll(string name, User currentUser, MainForm mainForm)
        {
            InitializeComponent();
            labelTitle.Text = name;
            this.Name = name;
            m_current_user = currentUser;
            m_mainForm = mainForm;
            m_startDefault = ConfigurationManager.AppSettings["StartPath"];
            m_CrewPayrollService = new CrewPayrollService();
            toolBarButtonRefresh.Click += new EventHandler(toolBarButtonRefresh_Click);
            toolBarButtonExcel.Click += new EventHandler(toolBarButtonExcel_Click);
            toolBarButtonRefresh_Click(null, null);
        }

        private void Search()
        {
            listViewAlert.Items.Clear();
            statusBar1.Text = "Total : 0 item(s)";
            IList softmarAlert = m_CrewPayrollService.GetAllPendingCrewPayroll(textBoxSearch.Text);
            LoadItems(softmarAlert);
        }

        void listViewAlert_DoubleClick(object sender, EventArgs e)
        {
            if (listViewAlert.SelectedItem == null) return;
            if (listViewAlert.SelectedItem.Tag == null) return;
            i_AGRESO_SYNC a = (i_AGRESO_SYNC)listViewAlert.SelectedItem.Tag;
            CompasCrewPayrollDetailForm adf = new CompasCrewPayrollDetailForm(a);
            adf.ShowDialog();
        }

        void toolBarButtonExcel_Click(object sender, EventArgs e)
        {

        }

        void toolBarButtonRefresh_Click(object sender, EventArgs e)
        {
            listViewAlert.Items.Clear();
            statusBar1.Text = "Total : 0 item(s)";
            IList softmarAlert = m_CrewPayrollService.GetAllPendingCrewPayroll();
            LoadItems(softmarAlert);
        }

        private void LoadItems(IList softmarAlert)
        {
            foreach (i_AGRESO_SYNC a in softmarAlert)
            {
                ListViewItem item = listViewAlert.Items.Add(a.AS_PICKUP_DATE_TIME); // alert date..
                item.SubItems.Add(a.AS_ID.ToString());
                item.SubItems.Add(a.AS_ADD_DATE.ToString("dd-MMM-yyyy"));
                item.SubItems.Add(a.remarks);
                item.SubItems.Add("Pending");
                item.Tag = a;
            }
            statusBar1.Text = string.Format("Total : {0} item(s)", softmarAlert.Count);
        }

        private void buttonSearch_Click(object sender, EventArgs e)
        {
            Search();
        }

        private void textBoxSearch_EnterKeyDown(object objSender, KeyEventArgs objArgs)
        {
            Search();
        }
    }
}